www.gusucode.com > VC++ 在线考试系统,AccessMSSQL-源码程序 > VC++ 在线考试系统,AccessMSSQL-源码程序\code\XZKS.cpp

    //Download by http://www.NewXing.com
// XZKS.cpp : implementation file
//

#include "stdafx.h"
#include "OnlineTest.h"
#include "XZKS.h"
#include "ADOC.h"
#include "ZXKS.h"
#include "USER.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern	CUSER	theUser;
/////////////////////////////////////////////////////////////////////////////
// CXZKS dialog


CXZKS::CXZKS(CWnd* pParent /*=NULL*/)
	: CDialog(CXZKS::IDD, pParent)
{
	//{{AFX_DATA_INIT(CXZKS)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	Number=1;
}


void CXZKS::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXZKS)
	DDX_Control(pDX, IDC_STATICXZ, m_XZ);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CXZKS, CDialog)
	//{{AFX_MSG_MAP(CXZKS)
	ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
	ON_BN_CLICKED(IDC_BUTTON_PRE, OnButtonPre)
	ON_BN_CLICKED(IDC_RADIOA, OnRadioa)
	ON_BN_CLICKED(IDC_RADIOB, OnRadiob)
	ON_BN_CLICKED(IDC_RADIOC, OnRadioc)
	ON_BN_CLICKED(IDC_RADIOD, OnRadiod)
	ON_BN_CLICKED(IDC_BUTTON_TIME, OnButtonTime)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXZKS message handlers

void CXZKS::OnButtonNext() 
{
	// TODO: Add your control notification handler code here
	string[Number]=Choice;
	if (string[Number]=='E') {
		AfxMessageBox("请选择");
		return ;
	}
//	CString str;
//	str.Format("%d ",Number);
//	AfxMessageBox(str);
	UpdateAnswer();
	Number++;
	Adoc.InitADOC();
	sql.Format("SELECT * FROM Exams WHERE ExamID='%s' AND Chioce=%d",ExamID,Number);
	m_pRecordset=Adoc.GetRecordSet((_bstr_t)sql);
	if (!m_pRecordset->adoEOF) {
		btnp->EnableWindow(TRUE);
		GetProblem();
		SetTest();
		Choice=GetAnswer(Number);
		SetInfor(Choice);
	}
	else
	{
		btnn->EnableWindow(FALSE);
		Dlg->XttsDlg.ShowWindow(SW_HIDE);
		Dlg->XzksDlg.ShowWindow(SW_HIDE);
		Dlg->KscjDlg.ShowWindow(SW_HIDE);
		Dlg->PdksDlg.MoveWindow(rect);
		Dlg->PdksDlg.ShowWindow(SW_SHOW);
		Dlg->m_Tab_Exam.SetCurSel(2);
		Dlg->PdksDlg.Next();
		Number--;		
	}
	Adoc.Break();
}

void CXZKS::SetTest() {
	m_XZ.SetWindowText(Question);
	CButton* btn=(CButton*)this->GetDlgItem(IDC_RADIOA);
	btn->SetWindowText(ChioceA);
	btn=(CButton*)this->GetDlgItem(IDC_RADIOB);
	btn->SetWindowText(ChioceB);
	btn=(CButton*)this->GetDlgItem(IDC_RADIOC);
	btn->SetWindowText(ChioceC);
	btn=(CButton*)this->GetDlgItem(IDC_RADIOD);
	btn->SetWindowText(ChioceD);
}

void CXZKS::Next() {
	Choice='0';
	Adoc.InitADOC();
	sql.Format("SELECT * FROM Exams WHERE ExamID='%s' AND Chioce=%d",ExamID,Number);
	m_pRecordset=Adoc.GetRecordSet((_bstr_t)sql);
	if (!m_pRecordset->adoEOF) {
		GetProblem();
		SetTest();
		Choice=GetAnswer(Number);
		SetInfor(Choice);
	}
	else 
		AfxMessageBox("题库无题");
	btnp->EnableWindow(FALSE);
	Adoc.Break();
}

void CXZKS::OnButtonPre() 
{
	// TODO: Add your control notification handler code here
	Number--;
	CString str;
	str.Format("%d ",Number);
	AfxMessageBox(str);
	Adoc.InitADOC();
	sql.Format("SELECT * FROM Exams WHERE ExamID='%s' AND Chioce=%d",ExamID,Number);
	m_pRecordset=Adoc.GetRecordSet((_bstr_t)sql);	
	if (!m_pRecordset->adoEOF&&Number>0) {
		btnn->EnableWindow(TRUE);
		GetProblem();
		SetTest();
		Choice=GetAnswer(Number);
		SetInfor(Choice);
	}
	else {
		MessageBox("已经是第一题了","系统提示");
		btnp->EnableWindow(FALSE);
		Number++;
	}
	Adoc.Break();
}

BOOL CXZKS::OnInitDialog() 
{
	CDialog::OnInitDialog();	
	// TODO: Add extra initialization here
	btnp=(CButton*)this->GetDlgItem(IDC_BUTTON_PRE);
	btnn=(CButton*)this->GetDlgItem(IDC_BUTTON_NEXT);
	bta=(CButton*)this->GetDlgItem(IDC_RADIOA);
	btb=(CButton*)this->GetDlgItem(IDC_RADIOB);
	btc=(CButton*)this->GetDlgItem(IDC_RADIOC);
	btd=(CButton*)this->GetDlgItem(IDC_RADIOD);
	for (int i=0;i<51;i++)
		Answer[i]='E';
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CXZKS::OnRadioa() 
{
	// TODO: Add your control notification handler code here
	Choice='A';
}

void CXZKS::OnRadiob() 
{
	// TODO: Add your control notification handler code here
	Choice='B';
}

void CXZKS::OnRadioc() 
{
	// TODO: Add your control notification handler code here
	Choice='C';
}

void CXZKS::OnRadiod() 
{
	// TODO: Add your control notification handler code here
	Choice='D';
}

void CXZKS::OnButtonTime() 
{
	// TODO: Add your control notification handler code here
	Dlg->Remain();
}

void CXZKS::SetInfor(char ch) {
	bta->SetCheck(FALSE);
	btb->SetCheck(FALSE);
	btc->SetCheck(FALSE);
	btd->SetCheck(FALSE);	
	switch(ch) {
		case 'A':bta->SetCheck(TRUE);break;
		case 'B':btb->SetCheck(TRUE);break;
		case 'C':btc->SetCheck(TRUE);break;
		case 'D':btd->SetCheck(TRUE);break;
		default:break;
	}
}

void CXZKS::GetProblem(){
	Question=(char*)(_bstr_t)m_pRecordset->GetCollect("Question");
	ChioceA=(char*)(_bstr_t)m_pRecordset->GetCollect("AnswerA");
	ChioceB=(char*)(_bstr_t)m_pRecordset->GetCollect("AnswerB");
	ChioceC=(char*)(_bstr_t)m_pRecordset->GetCollect("AnswerC");
	ChioceD=(char*)(_bstr_t)m_pRecordset->GetCollect("AnswerD");
}

char CXZKS::GetAnswer(int number) {
	sql.Format("SELECT * FROM TestInfor WHERE [IDNumber]='%s'",ID);
	m_pRecordset=Adoc.GetRecordSet((_bstr_t)sql);
	CString str;
	if (!m_pRecordset->adoEOF)
		str=(char*)(_bstr_t)m_pRecordset->GetCollect("AnswersC");
	else
		AfxMessageBox("无答案");
	strcpy(string,str);
	return string[number];
}

void CXZKS::UpdateAnswer() {
	Adoc.InitADOC();
	sql.Format("UPDATE TestInfor SET AnswersC='%s'WHERE IDNumber='%s'",string,ID);		
	Adoc.ExecuteSQL((_bstr_t)sql);
}
void CXZKS::OnOK() 
{
	// TODO: Add extra validation here
	Dlg->TestOver();
}

void CXZKS::OnCancel() 
{
	// TODO: Add extra cleanup here
	Dlg->XttsDlg.Cancel();
	CDialog::OnCancel();
}